﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;

namespace YouHP.Pages.Admin
{
    public class EditSymptom : YouHP.Pages.BasePage
    {
        protected SymptomInfo SymInfo { get; set; }

        protected override void ShowPage()
        {
            base.ShowPage();

            if (IsPost)
            {
                DoPost();
            }
            else
            {
                DoGet();
            }
        }

        private void DoGet()
        {
            int sid = RequestTools.GetQueryInt("sid", -1);
            if (sid <= 0)
            {
                AddErrLine("参数错误");
            }
            SymInfo = SymptomBLL.Instance.GetSymptomInfo(sid);
            if (SymInfo == null || SymInfo.Id != sid)
            {
                AddErrLine("疾病不存在");
            }
            if (this.ErrorCount > 0)
            {
                this.SetShowBackLink(true);
                return;
            }
        }

        protected void DoPost()
        {
            int symid = RequestTools.GetFormInt("symid", -1);
            string symname = RequestTools.GetFormString("symname");
            string symintro = RequestTools.GetFormString("symintro");
            string symdesp = RequestTools.GetFormString("symdesp");
            if (symid <= 0)
            {
                AddErrLine("参数错误");
            }
            if (symname == "" || symname.Length < 2)
            {
                AddErrLine("症状名称长度不能小于 2 ");
            }
            if (symintro == "" || symintro.Length < 2)
            {
                AddErrLine("症状简介长度不能小于 2 ");
            }
            if (symdesp == "" || symdesp.Length < 2)
            {
                AddErrLine("症状描述长度不能小于 2 ");
            }
            if (this.ErrorCount > 0)
            {
                this.SetShowBackLink(true);
                return;
            }

            SymptomInfo info = new SymptomInfo();
            info.Id = symid;
            info.Name = symname;
            info.Intro = symintro;
            info.Desp = symdesp;
            info.PinYin = Chinese.GetPingYinFirstLetter(info.Name);
            info.Type = 1;
            info.UpdateTime = DateTime.Now;
            SymptomBLL.Instance.UpdateSymptom(info);
            this.AddMsgLine("疾病修改成功");
            this.SetUrl("ListSymptoms.aspx");
            this.SetMetaRefresh(3, "ListSymptoms.aspx");

        }
    }
}
